package com.liuceng.zen.web.auth.listener;

import com.liuceng.zen.web.session.SessionRedisDao;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ShiroSessionListener implements SessionListener {
    private static final Logger logger = LoggerFactory.getLogger(ShiroSessionListener.class);

    private SessionRedisDao sessionDAO;

    public void setSessionDAO(SessionRedisDao sessionDAO) {
        this.sessionDAO = sessionDAO;
    }

    public void onExpiration(Session session) {
        sessionDAO.delete(session);
        // 会话过期时触发
        logger.info("ShiroSessionListener session {} 过期", session.getId());
    }

    public void onStart(Session session) {
        // 会话创建时触发
        logger.info("ShiroSessionListener session {} 被创建", session.getId()); // TODO
                                                                             // Auto-generated
                                                                             // method
                                                                             // stub
    }

    public void onStop(Session session) {
        sessionDAO.delete(session);
        // 会话被停止时触发
        logger.info("ShiroSessionListener session {} 被销毁", session.getId());
    }

}
